home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / TIMING.SWG / 0003_Re: seconds since midnight.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  1.8 KB  |  72 lines

  1. {
  2. I tried this but the two (my original procedure and your code) produce
  3. slightly different values.  Compile this and run in DOS:
  4. }
  5. uses dos;
  6.  
  7. function timer:real;
  8. var r:registers; h,m,s,t:real;
  9. begin
  10.   r.ax:=44*256;
  11.   msdos(dos.registers(r));
  12.   h:=(r.cx div 256);
  13.   m:=(r.cx mod 256);
  14.   s:=(r.dx div 256);
  15.   t:=(r.dx mod 256);
  16.   timer:=h*3600+m*60+s+t/100;
  17. end;
  18.  
  19. function timer2:real;
  20. begin
  21.   timer2:=meml[$0040:$006c]/18.2;
  22. end;
  23.  
  24. begin
  25.   write(^M^J'Ctrl-Break to Quit'^M^J^M^J+
  26.         'Int 21h Version  $0040:$006C Version'^M^J+
  27.         '---------------  -------------------'^M^J);
  28.   repeat
  29.     write(timer2:3:5,'      ',timer:3:5,^M);
  30.   until false=true;
  31. end.
  32.  
  33. ... and tell me if you notice the difference as well.  I tried swapping
  34. the timer and timer2 positions in the write() function to see if it was
  35. just the difference between the time the two functions are executed and
  36. it was not caused by that.
  37.  
  38. brian.petersen@604.sasbbs.com
  39.  
  40. {
  41.  BP> Could someone please convert this to BASM?  It returns the number of
  42.  BP> seconds since midnight in the form of a real variable.
  43.  
  44.  BP> function timer:real;
  45.  BP> var r:registers; h,m,s,t:real;
  46.  BP> begin
  47.  BP>   r.ax:=$2c00;
  48.  BP>   msdos(r);
  49.  BP>   h:=(r.cx div 256);
  50.  BP>   m:=(r.cx mod 256);
  51.  BP>   s:=(r.dx div 256);
  52.  BP>   t:=(r.dx mod 256);
  53.  BP>   timer:=h*3600+m*60+s+t/100;
  54.  BP> end;
  55. }
  56. I think, that's the way it should be optimized (and corrected). Everything
  57. else would be overkill:
  58.     function timer:longint;
  59.     { returns number of 1/100 s since midnight }
  60.     var dostime:record t,s,m,h:byte end;
  61.     begin
  62.       asm
  63.         mov ax, 2c00h
  64.         int 21h
  65.         mov word ptr dostime.m, cx
  66.         mov word ptr dostime.t, dx
  67.       end;
  68.       with dostime do
  69.         timer:=(longint(h*60+m)*60+s)*100+t
  70.     end;
  71.  
  72.